<%--

Copyright 2010 mazhao.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
under the License.

  User: mazhao
  Date: 2010/11/17
  Time: 1:07:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>

    <title>User Management</title>
    <script type="text/javascript">
        function changeRole(userId, roleId) {
            $.jGrowl("change role of " + userId + " to " + roleId);
            $.post("<%=request.getContextPath()%>/management/onthefly/changerole.action",
                {"username":userId, "role": roleId}, changeRoleRtn, "json");

        }

        function changeRoleRtn(data) {
            $.jGrowl("change role return " + data.onTheFlyMessage + " data.onTheFlyStatus");
        }

        function enableUser(userId, status) {
            if (status) {
                $.jGrowl("enable user " + userId);
                $.post("<%=request.getContextPath()%>/management/onthefly/userenable.action",
                                {"username":userId, "status": true}, enableUserRtn, "json");

            } else {
                $.jGrowl("disable user " + userId);
                $.post("<%=request.getContextPath()%>/management/onthefly/userenable.action",
                                                {"username":userId, "status": false}, enableUserRtn, "json");
            }
        }

        function enableUserRtn(data) {
            $.jGrowl("enable user return " + data.onTheFlyMessage + " data.onTheFlyStatus");

        }
    </script>

</head>
<body>
<div >
    <h3>User List</h3><table align="left">
        <thead>
        <tr>
            <td>Name</td>
            <td>Province</td>
            <td>City</td>
            <td>Post Code</td>
            <td>Address</td>
            <td>Name</td>
            <td>Phone</td>
            <td>Cell Phone</td>
            <td>E-Mail</td>

            <td>Role</td>
            <td>Status</td>
        </tr>
        </thead>
        <tbody>
        <s:iterator value="users" var="user">
            <tr>
                <td><s:property value="username"/></td>
                <td><s:property value="province"/></td>
                <td><s:property value="city"/></td>
                <td><s:property value="postCode"/></td>
                <td><s:property value="address"/></td>
                <td><s:property value="name"/></td>
                <td><s:property value="phone"/></td>
                <td><s:property value="cellPhone"/></td>
                <td><s:property value="email"/></td>

                <td>
                    <s:select list="%{ roles }" listKey="id" listValue="name" theme="simple" name="role" value="roleId"
                              onchange="changeRole( this.parentNode.parentNode.childNodes[1].innerText  , this.options[this.selectedIndex].value)"/>
                    <!--
                    <s:property value="role"/> (<s:property value="roleId"/>)
                    -->
                </td>
                <td>
                    <s:checkbox name="status" value="status" label="Enabled" theme="simple"
                                onchange="enableUser(this.parentNode.parentNode.childNodes[1].innerText, this.checked)"/>
                    Enabled
                    <!--
                    <s:property value="status"/>
                    -->
                </td>
            </tr>
        </s:iterator>
        </tbody>
    </table>
</div>
</body>
</html>